package d0323;

import java.io.*;

public class ByteArrayBufferTest {
    private static byte[] mybuffer;
    //将数据写入内存
    public static void main(String[] args) {
        writeBuffer();
        readBuffer();
    }

    private static void readBuffer() {
        ByteArrayInputStream bais = new ByteArrayInputStream(mybuffer);
        DataInputStream dis = new DataInputStream(bais);
        try {
            System.out.println(dis.readInt()+"\t" + dis.readDouble()+"\t"+ dis.readUTF());
            dis.close();
            bais.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private static void writeBuffer() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        try {
            dos.writeInt(100);
            dos.writeDouble(3.14);
            dos.writeUTF("icss");
            mybuffer = baos.toByteArray();
            dos.close();
            baos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}